package hammersmith.local.valueobjects;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class CustomTableRenderer extends DefaultTableCellRenderer {
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		Component cell = super.getTableCellRendererComponent(table, value,
				isSelected, hasFocus, row, column);
		
		setHorizontalAlignment( JLabel.CENTER );

		try {

			if (isSelected == false) {

				if (column == 5) {

					if (value instanceof String) {
						if (Integer.parseInt((String) value) > 10) {
							cell.setBackground(Color.green);
						} else if (Integer.parseInt((String) value) > 0
								&& Integer.parseInt((String) value) <= 10) {
							cell.setBackground(Color.yellow);
						} else {
							cell.setBackground(Color.red);
						}
					}
				} else {
					cell.setBackground(Color.white);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cell;
	}
}